package pku;


import java.util.Arrays;

/**
 * 消息的实现
 */
public class DefaultMessage implements ByteMessage {

    private DefaultKeyValue headers = new DefaultKeyValue(16);

    private byte[] body;

    public void clear() {
        this.headers.clear();
    }

    public void setHeaders(DefaultKeyValue headers) {
        this.headers = headers;
    }

    public DefaultMessage(byte[] body) {
        this.body = body;
    }

    public DefaultMessage() {
        super();
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public KeyValue headers() {
        return headers;
    }


    public DefaultMessage putHeaders(String key, int value) {
        headers.put(key, value);
        return this;
    }

    public DefaultMessage putHeaders(String key, long value) {
        headers.put(key, value);
        return this;
    }

    public DefaultMessage putHeaders(String key, double value) {
        headers.put(key, value);
        return this;
    }

    public DefaultMessage putHeaders(String key, String value) {
        headers.put(key, value);
        return this;
    }

    @Override
    public String toString() {
        return "DefaultMessage{" +
                "headers=" + headers +
                ", body=" + Arrays.toString(body) +
                '}';
    }
}
